home *** CD-ROM | disk | FTP | other *** search
/ Clickx 47 / Clickx 47.iso / assets / software / sswitchxp152.exe / source / SpeedswitchXP / PowerCapabilities.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-07-12  |  6.8 KB  |  244 lines

  1. /*
  2.    SpeedswitchXP V1.5
  3.    - Windows XP CPU Frequency Control for Notebooks -
  4.  
  5.    Copyright(c) 2002-2006 Christian Diefer
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License version 2 as 
  9.    published by the Free Software Foundation.
  10.    
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.    
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #define _UNICODE
  22.  
  23. #include "stdafx.h"
  24. #include "SpeedswitchXP.h"
  25. #include "speedswitch.h"
  26. #include "PowerCapabilities.h"
  27.  
  28.  
  29. // CPowerCapabilities dialog
  30.  
  31. IMPLEMENT_DYNAMIC(CPowerCapabilities, CDialog)
  32. CPowerCapabilities::CPowerCapabilities(CWnd* pParent /*=NULL*/)
  33.     : CDialog(CPowerCapabilities::IDD, pParent)
  34.   , m_szPowerButton(_T(""))
  35.   , m_szSleepButton(_T(""))
  36.   , m_szLidSwitch(_T(""))
  37.   , m_szSStates(_T(""))
  38.   , m_szHiberFile(_T(""))
  39.   , m_szWakeSupport(_T(""))
  40.   , m_szVideoDim(_T(""))
  41.   , m_szAPMBios(_T(""))
  42.   , m_szThermalZones(_T(""))
  43.   , m_szThrottle(_T(""))
  44.   , m_szUPSPresent(_T(""))
  45.   , m_szThrottleMax(_T(""))
  46.   , m_szThrottleMin(_T(""))
  47.   , m_szSpinDown(_T(""))
  48.   , m_szSystemBatteries(_T(""))
  49.   , m_szShortTermBatteries(_T(""))
  50.   yes.LoadStringW( IDS_PINF19 );
  51.   no.LoadStringW( IDS_PINF20 );
  52. }
  53.  
  54. CPowerCapabilities::~CPowerCapabilities()
  55. { }
  56.  
  57. void CPowerCapabilities::DoDataExchange(CDataExchange* pDX)
  58. {
  59.   CDialog::DoDataExchange(pDX);
  60.   DDX_Control(pDX, IDC_LIST1, m_cList);
  61. }
  62.  
  63.  
  64. BEGIN_MESSAGE_MAP(CPowerCapabilities, CDialog)
  65. END_MESSAGE_MAP()
  66.  
  67.  
  68. // CPowerCapabilities message handlers
  69. BOOL CPowerCapabilities::OnInitDialog()
  70. {
  71.   CDialog::OnInitDialog();
  72.  
  73.   yes.LoadStringW( IDS_PINF19 );
  74.   no.LoadStringW( IDS_PINF20 );
  75.  
  76.   CRect rect;
  77.   m_cList.GetClientRect( &rect );
  78.   int nColInterval = rect.Width()/8;
  79.  
  80.   CString s1;
  81.   s1.LoadStringW( IDS_PINF1 );
  82.  
  83.   m_cList.InsertColumn( 0, s1, LVCFMT_LEFT, nColInterval*3 );
  84.  
  85.   s1.LoadStringW( IDS_PINF2 );
  86.   m_cList.InsertColumn( 1, s1, LVCFMT_LEFT, nColInterval*4+nColInterval/2 );
  87.  
  88.   s1.LoadStringW( IDS_PINF3 );
  89.   int nIndex = m_cList.InsertItem( 0, s1 );
  90.   m_cList.SetItemText( nIndex, 1, m_szPowerButton );
  91.  
  92.   s1.LoadStringW( IDS_PINF4 );
  93.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  94.   m_cList.SetItemText( nIndex, 1, m_szSleepButton );
  95.  
  96.   s1.LoadStringW( IDS_PINF5 );
  97.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  98.   m_cList.SetItemText( nIndex, 1, m_szLidSwitch );
  99.  
  100.   s1.LoadStringW( IDS_PINF6 );
  101.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  102.   m_cList.SetItemText( nIndex, 1, m_szSStates );
  103.  
  104.   s1.LoadStringW( IDS_PINF7 );
  105.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  106.   m_cList.SetItemText( nIndex, 1, m_szHiberFile );
  107.  
  108.   s1.LoadStringW( IDS_PINF8 );
  109.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  110.   m_cList.SetItemText( nIndex, 1, m_szWakeSupport );
  111.  
  112.   s1.LoadStringW( IDS_PINF9 );
  113.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  114.   m_cList.SetItemText( nIndex, 1, m_szVideoDim );
  115.  
  116.   s1.LoadStringW( IDS_PINF10 );
  117.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  118.   m_cList.SetItemText( nIndex, 1, m_szAPMBios );
  119.  
  120.   s1.LoadStringW( IDS_PINF11 );
  121.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  122.   m_cList.SetItemText( nIndex, 1, m_szUPSPresent );
  123.  
  124.   s1.LoadStringW( IDS_PINF12 );
  125.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  126.   m_cList.SetItemText( nIndex, 1, m_szThermalZones );
  127.  
  128.   s1.LoadStringW( IDS_PINF13 );
  129.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  130.   m_cList.SetItemText( nIndex, 1, m_szThrottle );
  131.  
  132.   if( m_szThrottle == yes )
  133.   {
  134.     s1.LoadStringW( IDS_PINF14 );
  135.     nIndex = m_cList.InsertItem( nIndex+1, s1 );
  136.     m_cList.SetItemText( nIndex, 1, m_szThrottleMin + _T("%") );
  137.  
  138.     s1.LoadStringW( IDS_PINF15 );
  139.     nIndex = m_cList.InsertItem( nIndex+1, s1 );
  140.     m_cList.SetItemText( nIndex, 1, m_szThrottleMax + _T("%") );
  141.   }
  142.  
  143.   s1.LoadStringW( IDS_PINF16 );
  144.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  145.   m_cList.SetItemText( nIndex, 1, m_szSpinDown );
  146.  
  147.   s1.LoadStringW( IDS_PINF17 );
  148.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  149.   m_cList.SetItemText( nIndex, 1, m_szSystemBatteries );
  150.  
  151.   s1.LoadStringW( IDS_PINF18 );
  152.   nIndex = m_cList.InsertItem( nIndex+1, s1 );
  153.   m_cList.SetItemText( nIndex, 1, m_szShortTermBatteries );
  154.  
  155.   return TRUE;
  156. }
  157.  
  158. void CPowerCapabilities::setVars()
  159. {
  160.   yes.LoadStringW( IDS_PINF19 );
  161.   no.LoadStringW( IDS_PINF20 );
  162.  
  163.   BOOL x = (CallNtPowerInformation(SystemPowerCapabilities,
  164.                                    NULL,
  165.                                    0,
  166.                                    &spc,
  167.                                    sizeof(spc)) == ERROR_SUCCESS);
  168.   if( x )
  169.   {
  170.     m_szPowerButton = (spc.PowerButtonPresent ? yes : no );
  171.     m_szSleepButton = (spc.SleepButtonPresent ? yes : no );
  172.     m_szLidSwitch = (spc.LidPresent ? yes : no );
  173.  
  174.     wchar_t text[128] = _T("");
  175.     bool first = true;
  176.  
  177.     if( spc.SystemS1 ) 
  178.     {
  179.       _tcscat_s( text, _T("S1") );
  180.       first = false;
  181.     }
  182.  
  183.     if( spc.SystemS2 )
  184.     {
  185.       if( !first )
  186.         _tcscat_s( text, _T(", ") );
  187.       _tcscat_s( text, _T("S2") );
  188.       first = false;
  189.     }
  190.  
  191.     if( spc.SystemS3 )
  192.     {
  193.       if( !first )
  194.         _tcscat_s( text, _T(", ") );
  195.       _tcscat_s( text, _T("S3") );
  196.       first = false;
  197.     }
  198.  
  199.     if( spc.SystemS4 )
  200.     {
  201.       if( !first )
  202.         _tcscat_s( text, _T(", ") );
  203.       _tcscat_s( text, _T("S4") );
  204.       first = false;
  205.     }
  206.  
  207.     if( spc.SystemS5 )
  208.     {
  209.       if( !first )
  210.         _tcscat_s( text, _T(", ") );
  211.       _tcscat_s( text, _T("S5") );
  212.       first = false;
  213.     }
  214.     
  215.     m_szSStates = text;
  216.     m_szHiberFile = (spc.HiberFilePresent ? yes : no );
  217.     m_szWakeSupport = (spc.FullWake ? yes : no );
  218.     m_szVideoDim = (spc.VideoDimPresent ? yes : no );
  219.     m_szAPMBios = (spc.ApmPresent ? yes : no );
  220.     m_szUPSPresent = (spc.UpsPresent ? yes : no );
  221.     m_szThermalZones = (spc.ThermalControl ? yes : no );
  222.  
  223.     BOOLEAN throttle = spc.ProcessorThrottle;
  224.  
  225.     m_szThrottle = (throttle ? yes : no);
  226.  
  227.     if( throttle )
  228.     {
  229.       m_szThrottleMax.Format( _T("%d"), spc.ProcessorMinThrottle );
  230.       m_szThrottleMin.Format( _T("%d"), spc.ProcessorMaxThrottle );
  231.     }
  232.     else
  233.     {
  234.       m_szThrottleMax = _T("---");
  235.       m_szThrottleMin = _T("---");
  236.     }
  237.  
  238.     m_szSpinDown = (spc.DiskSpinDown ? yes : no );
  239.     m_szSystemBatteries = (spc.SystemBatteriesPresent ? yes : no );
  240.     m_szShortTermBatteries = (spc.BatteriesAreShortTerm ? yes : no );
  241.   }
  242. }
  243.